from selenium.webdriver.common.by import By
from base.base import Base

class PageLogin(Base):

    
    username_locator = (By.NAME,'username')
    password_locator = (By.NAME,'password')
    captcha_locator = (By.NAME,'captchaAnswer')
    login_button_locator = (By.XPATH,'(//button)[2]')
    username_error_message_locator = (By.XPATH,'(//div[@class="el-form-item__error"])[1]')
    password_error_message_locator = (By.XPATH,'(//div[@class="el-form-item__error"])[2]')
    captcha_error_message_locator = (By.XPATH,'(//div[@class="el-form-item__error"])[3]')
    top_error_message_locator = (By.CLASS_NAME,'el-message__content')

    def enter_username(self,name):
        self.input(self.username_locator,name)

    def enter_password(self,password):
        self.input(self.password_locator,password)

    def enter_captcha(self,captcha):
        self.input(self.captcha_locator,captcha)

    def click_login_button(self):
        self.click(self.login_button_locator)

    def get_username_error_message(self):
        return self.get_text(self.username_error_message_locator)
        

    def get_password_error_message(self):
        return self.get_text(self.password_error_message_locator)

    def get_captcha_error_message(self):
        return self.get_text(self.captcha_error_message_locator)

    def get_top_error_message(self):
        return self.get_text(self.top_error_message_locator)